package com.xiaode.interceptor;

import java.lang.reflect.Parameter;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.Kv;
import cn.hutool.core.util.StrUtil;


public class ParaToKvInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller c = inv.getController();
		
		Parameter[] ps = inv.getMethod().getParameters();
		if(ps.length > 0) {
			Kv kv = Kv.create();
			for(int i = 0; i < ps.length; i++) {
				kv.setIfNotNull(ps[i].getName(), inv.getArg(i));
			}
			c.set("ParaKv", kv);
		}
		inv.invoke();
	}
	
	
	public static void main(String[] args) {
		int[] is = StrUtil.splitToInt("123_12_5_1_", "_");
		System.out.println(is[is.length-2]);
		System.out.println(is.length);
	}

}
